tongfusoft.serverFileList = function() {
}

tongfusoft.serverFileList.prototype = {
		openFileListPage:function(){
			
			$('#dialogMode').modal('show');
			new  tongfusoft.serverFileList().fileList();
		},
		fileList:function(){
			
			
			common.post("bigFile/query", {length:-1, start:0, draw:0}, function(data) {
				var dataHtml='';
				$.each(data.data,function(index,item){
					
					
					
					
					dataHtml=dataHtml+'<div class="list-group-item">';
					dataHtml=dataHtml+'<div class="media-box">';
					dataHtml=dataHtml+'<div class="pull-left">';
					dataHtml=dataHtml+'<label class="radio-inline c-radio"> ';
					dataHtml=dataHtml+'<input id="selectFileRadio'+item.id+'" fileName="'+item.fileName+'" type="radio" name="selectFileRadio" value="'+item.id+'" /> ';
					dataHtml=dataHtml+'<span class="fa fa-circle"></span>';
					dataHtml=dataHtml+'</label> ';
					dataHtml=dataHtml+'</div>';
					dataHtml=dataHtml+'<div class="media-box-body clearfix">';
					dataHtml=dataHtml+'<div class="media-box-heading">'+item.fileName;
					dataHtml=dataHtml+'</div>';
					dataHtml=dataHtml+'</div>';
					dataHtml=dataHtml+'</div>';
					dataHtml=dataHtml+'</div>';
				});
				$("#serverDataList").empty();
				$("#serverDataList").html(dataHtml);
			});
		},
		selectedFile:function(){
			$("#selectedBtn").click(function() {
				$("#selectFileId").val($('input:radio[name="selectFileRadio"]:checked').val());
				$("#selectFileName").val($('input:radio[name="selectFileRadio"]:checked').attr("fileName"));
				$('#dialogMode').modal('hide');

			})
			
			
		},
		openFolderPage:function(){
			$("#openFolderBtn").click(function(){
				new  tongfusoft.serverFileList().foldersList();
				$('#serverFolderMode').modal('show');
				
			});
			
			
		},
		selectFolderBtn:function(){
			
			$("#selectFolderBtn").click(function() {
				$('#serverFolderMode').modal('hide');

			})
		},
		treeAllParent:function(node){
			
			if(typeof(node.parentId)=='undefined'){
				
				return '';
			}
			var parent = $('#treeview2').treeview('getParent', node);
			var path=parent.text+'/';
			if(typeof(parent.parentId)!='undefined'){
				path=this.treeAllParent(parent)+path;	
			}
			
			
			
			return path;
		},
		foldersList : function() {
			common.post('folders/list', {}, function(data) {
				$('#treeview2').treeview('remove');
				if (data.state == 'success') {
					
					var defaultData = [ {
						text : data.data.text,
						href : data.data.href,
						tags : data.data.tags,
						nodes : data.data.nodes
					} ];
					
					var defaultDataee = eval(defaultData)

					$('#treeview2').treeview({
						
						data : defaultDataee,
						showTags : true,
						onNodeSelected:function(event, node){
							$("#folderPath").val('/'+new tongfusoft.serverFileList().treeAllParent(node)+node.text);
							$("#selectFolderId").val(node.tags[0]);
						
						}
					});

				}
			});
		}
}